<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        td {
            padding: 20px 40px;
        }

        table,
        td {
            border-collapse: collapse;
        }

        table tr:nth-child(odd) {
            background: red;
        }

        table tr:nth-child(even) {
            background: blue;
        }
    </style>
</head>

<body>
    <table border="1">
        <tr>
            <td></td>
            <td></td>
            <td></td>
        </tr>
        <tr>
            <td></td>
            <td></td>
            <td></td>
        </tr>
        <tr>
            <td></td>
            <td></td>
            <td></td>
        </tr>
        <tr>
            <td></td>
            <td></td>
            <td></td>
        </tr>
    </table>
    <script>
        let td = document.querySelectorAll('td');
        td.forEach(item => {
            item.onclick = function () {
                this.style.background = 'green';
            }
        }) 
    </script>
</body>

</html>